home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue63 / Debug / Demos / ScannerDemoUnit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-10-02  |  2.4 KB  |  98 lines

  1. unit ScannerDemoUnit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Menus, StdCtrls,
  8.   HVBorDebug, BorDebugScanners, BorDebugDumpScanner, ComCtrls;
  9.  
  10. type
  11.   TScannerDemoForm = class(TForm)
  12.     MainMenu: TMainMenu;
  13.     FileMenu: TMenuItem;
  14.     OpenItem: TMenuItem;
  15.     ExitItem: TMenuItem;
  16.     N1: TMenuItem;
  17.     OpenDialog: TOpenDialog;
  18.     Memo: TMemo;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure OpenItemClick(Sender: TObject);
  21.     procedure ExitItemClick(Sender: TObject);
  22.     procedure FormDestroy(Sender: TObject);
  23.   private
  24.     Debug: TBorDebug;
  25.     DumpScanner: TDumpBorDebugScanner;
  26.     Dump: string;
  27.     DumpPos: integer;
  28.     procedure ScanIt;
  29.     procedure OnScannerDump(Sender: TObject; const Msg: string);
  30.   public
  31.   end;
  32.  
  33. var
  34.   ScannerDemoForm: TScannerDemoForm;
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. procedure TScannerDemoForm.FormCreate(Sender: TObject);
  41. begin
  42.   Debug := TBorDebug.Create;
  43.   DumpScanner := TDumpBorDebugScanner.Create(Debug);
  44.   DumpScanner.OnDump := OnScannerDump;
  45. end;
  46.  
  47. procedure TScannerDemoForm.FormDestroy(Sender: TObject);
  48. begin
  49.   DumpScanner.Free;
  50.   Debug.Free;
  51. end;
  52.  
  53. procedure TScannerDemoForm.OnScannerDump(Sender: TObject; const Msg: string);
  54. var
  55.   NewLength : integer;
  56. begin
  57.   // Grow the dump buffer if it is too small
  58.   if (Length(Dump) - DumpPos) < Length(Msg) then
  59.   begin
  60.     if Length(Msg) > Length(Dump)
  61.     then NewLength := Length(Dump) + Length(Msg)
  62.     else NewLength := Length(Dump) * 2;
  63.     SetLength(Dump, NewLength);
  64.   end;
  65.   // Just move the contest quickly over to the dump buffer
  66.   Move(Pointer(Msg)^, Pointer(@Dump[DumpPos+1])^, Length(Msg));
  67.   // Update our position in the dump buffer
  68.   Inc(DumpPos, Length(Msg));
  69. end;
  70.  
  71. procedure TScannerDemoForm.ScanIt;
  72. begin
  73.   SetLength(Dump, 4*1024*1024); // 4Meg!
  74.   DumpPos := 0;
  75.   DumpScanner.Scan([soModule, soAlignSym, soSrcModule, soGlobalSym, soGlobalPub,
  76.     soGlobalTypes, soNames, soBrowse, soSrcModuleRanges, soSrcModuleFiles]);
  77.   SetLength(Dump, DumpPos);
  78.   Memo.Lines.Text := Dump;
  79.   Dump := '';
  80. end;
  81.  
  82. procedure TScannerDemoForm.OpenItemClick(Sender: TObject);
  83. begin
  84.   if OpenDialog.Execute then
  85.   begin
  86.     Debug.Filename := OpenDialog.Filename;
  87.     Debug.Open;
  88.     ScanIt;
  89.   end;
  90. end;
  91.  
  92. procedure TScannerDemoForm.ExitItemClick(Sender: TObject);
  93. begin
  94.   Close;
  95. end;
  96.  
  97. end.
  98.